package com.wwj.auction.login.controller;


import com.wwj.auction.common.result.R;
import com.wwj.auction.login.service.WithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wwj
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/login/withdraw")
@Slf4j
@Api("提现流程")
public class WithdrawController {

    @Autowired
    private WithdrawService withdrawService;

    @ApiOperation("处理提现流程")
    @GetMapping("/auth/commitWithdraw/{userId}/{fetchAmt}")
    public R commitWithdraw(
            @PathVariable("userId") Integer userId,
            @PathVariable("fetchAmt") String fetchAmt) {
        // 用户进行余额提现，将提现信息进行保存
        withdrawService.save(userId, fetchAmt);
        return R.ok().message("提现申请已受理");
    }

    @ApiOperation("查询当前用户的提现状态")
    @GetMapping("/status/{userId}")
    public R status(@PathVariable("userId") Integer userId) {
        Integer status = withdrawService.getStatus(userId);
        return R.ok().data("status", status);
    }
}

